import { SPoint } from "../../../../../../Message/Public/SPoint";
import { MonsterPlayer } from "../../../../scene/player/entity/MonsterPlayer";
import { CrossDefenceTowerInfo } from "../data/CrossDefenceTowerInfo";
import { Language } from "../../../../../../extend/language/Language";
import { Cache } from "../../../../cache/Cache";
import { Global } from "../../../../../../com/gengine/global/Global";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { Alert } from "../../../../../../com/mui/controls/Alert";
import { ObjCreate } from "../../../common/ObjCreate";
import { AutoLayoutTextContainer } from "../../../../../common/text/AutoLayoutTextContainer";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { ScaleBitmap } from "../../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class CrossDefenceCopyUpgradeMenu
    
    export  class CrossDefenceCopyUpgradeMenu /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            this._btnUpgrade.addEventListener(flash.events.MouseEvent.CLICK, this.clickUpgradeHandler);
            this._btnRecycle.addEventListener(flash.events.MouseEvent.CLICK, this.clickRecycleHandler);
            this.addEventListener(flash.events.MouseEvent.CLICK, this.clickMeHandler);
            this._btnClose.addEventListener(flash.events.MouseEvent.CLICK, this.clickCloseHandler);
            return;
        }

        public get gridePoint(): SPoint
        {
            return this._gridePoint;
        }

        public updateView(arg1: MonsterPlayer, arg2: CrossDefenceTowerInfo, arg3: Boolean): void
        {
            var loc1=null;
            this._player = arg1;
            this._info = arg2;
            if (arg3) 
            {
                loc1 = this._player.localToGlobal(new Object /* flash.geom.Point */(0, 0));
                this.x = loc1.x + 30;
                this.y = loc1.y - 180;
                this._gridePoint = arg1.entityInfo.entityInfo.points[0] as SPoint;
            }
            this.doReflash();
            return;
        }

        public reflashView(arg1: CrossDefenceTowerInfo): void
        {
            this._info = arg1;
            this.doReflash();
            return;
        }

        public doReflash(): void
        {
            var loc5=null;
            var loc6=null;
            if (this._info == null) 
            {
                return;
            }
            this._txtContainer.setText(0, this._info.name + "    Lv" + this._info.level.toString());
            this._txtContainer.setText(1, Language.getStringByParam(80298, this._info.owner));
            this._txtContainer.setText(2, Language.getStringByParam(80299, this._info.curEffectDesc));
            if (Cache.instance.crossDefenceCopy.isInDifficulty()) 
            {
                loc5 = Language.getString(20400);
                if ((loc6 = Cache.instance.crossDefenceCopy.getMyBlessEffectByTowerType(this._info.config.type)) != null) 
                {
                    loc5 = loc6.describe;
                }
                this._txtContainer.setText(3, Language.getStringByParam(80331, loc5));
                this._txtContainer.setText(4, Language.getStringByParam(80300, this._info.nextEffectDesc));
                this._txtContainer.setText(5, Language.getStringByParam(80301, this._info.levelUpNeed));
                this._txtContainer.setText(6, Language.getStringByParam(80302, this._info.recycleBack));
            }
            else 
            {
                this._txtContainer.setText(3, Language.getStringByParam(80300, this._info.nextEffectDesc));
                this._txtContainer.setText(4, Language.getStringByParam(80301, this._info.levelUpNeed));
                this._txtContainer.setText(5, Language.getStringByParam(80302, this._info.recycleBack));
            }
            var loc1=Language.getString(80297) == this._info.nextEffectDesc;
            var loc2=Cache.instance.crossDefenceCopy.myMaterial >= this._info.levelUpNeed;
            var loc3=this._info.owner == Cache.instance.role.entityInfo.name;
            if (loc1 || !loc2 || !loc3) 
            {
                this._btnUpgrade.enabled = false;
                this._btnUpgrade.mouseEnabled = false;
            }
            else 
            {
                this._btnUpgrade.enabled = true;
                this._btnUpgrade.mouseEnabled = true;
            }
            if (loc3) 
            {
                this._btnRecycle.enabled = true;
                this._btnRecycle.mouseEnabled = true;
            }
            else 
            {
                this._btnRecycle.enabled = false;
                this._btnRecycle.mouseEnabled = false;
            }
            var loc4=this._txtContainer.getTextByIndex(5);
            this._btnUpgrade.y = loc4.y + this._txtContainer.y - 2;
            if (Cache.instance.crossDefenceCopy.isInDifficulty()) 
            {
                loc4 = this._txtContainer.getTextByIndex(6);
            }
            this._btnRecycle.x = loc4.x + this._txtContainer.x;
            this._btnRecycle.y = loc4.y + this._txtContainer.y + 25;
            this._bg.height = this._txtContainer.height + 48;
            return;
        }

        public getCurTower(): MonsterPlayer
        {
            return this._player;
        }

        public getCurInfo(): CrossDefenceTowerInfo
        {
            return this._info;
        }

        public /* override */ set x(arg1: number)
        {
            super.x = arg1;
            if (this.x <= 10) 
            {
                super.x = 10;
            }
            if (this.x + this.width >= Global.stage.stageWidth - 10) 
            {
                super.x = Global.stage.stageWidth - 10 - this.width;
            }
            return;
        }

        public /* override */ set y(arg1: number)
        {
            super.y = arg1;
            if (this.y <= 10) 
            {
                super.y = 10;
            }
            if (this.y + this.height >= Global.stage.stageHeight - 10) 
            {
                super.y = Global.stage.stageHeight - 10 - this.height;
            }
            return;
        }

        /* internal  */clickUpgradeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (flash.utils.getTimer() < this._nextClickUpgradeTime) 
            {
                return;
            }
            this._nextClickUpgradeTime = flash.utils.getTimer() + 700;
            Dispatcher.dispatchEvent(new DataEvent(EventName.ReqCrossDefenceCopyUpgradeTower, this._player));
            return;
        }

        /* internal  */clickRecycleHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Language.getStringByParam(80315, this._info.name, this._info.level, this._info.recycleBack);
            Alert.show(loc1, null, Alert.OK | Alert.CANCEL, null, this.closeRecycleAlertHandler);
            return;
        }

        /* internal  */closeRecycleAlertHandler(arg1: int): void
        {
            if (arg1 != Alert.OK) 
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.ReqCrossDefenceCopyRecycleTower, this._player));
            return;
        }

        /* internal  */clickCloseHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CrossDefenceCloseUpdateMenu));
            return;
        }

        /* internal  */clickMeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */initView(): void
        {
            this._bg = ObjCreate.createBg(0, 0, this.WinWidth, this.WinHeight, this);
            this._txtContainer = new AutoLayoutTextContainer();
            this._txtContainer.x = 18;
            this._txtContainer.y = 8;
            this.addChild(this._txtContainer);
            this._txtContainer.addNewText(this.WinWidth, "", 15, 16776960, flash.text.TextFieldAutoSize.CENTER);
            var loc1=this._txtContainer.getTextByIndex(0);
            var loc2=loc1.defaultTextFormat;
            loc2.bold = true;
            loc1.defaultTextFormat = loc2;
            this._txtContainer.addNewText(260);
            this._txtContainer.addNewText(260);
            if (Cache.instance.crossDefenceCopy.isInDifficulty()) 
            {
                this._txtContainer.addNewText();
            }
            this._txtContainer.addNewText(260);
            this._txtContainer.addNewText();
            this._txtContainer.addNewText();
            this._btnUpgrade = ObjCreate.createGButton(Language.getString(57110), 165, -2, 50, 26, this);
            this._btnRecycle = ObjCreate.createGButton(Language.getString(80303), 0, 20, 50, 26, this, "ButtonRedMini");
            this._btnClose = ObjCreate.createGButton("", 255, 6, 27, 28, this, "RedBigXCloseBtn");
            return;
        }

        /* internal */ /* const */WinWidth: int=300;

        /* internal */ /* const */WinHeight: int=240;

        /* internal */ /* var */_btnUpgrade: GButton;

        /* internal */ /* var */_nextClickUpgradeTime: int;

        /* internal */ /* var */_btnRecycle: GButton;

        /* internal */ /* var */_btnClose: GButton;

        /* internal */ /* var */_txtContainer: AutoLayoutTextContainer;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_player: MonsterPlayer;

        /* internal */ /* var */_info: CrossDefenceTowerInfo;

        /* internal */ /* var */_gridePoint: SPoint;
    }
